package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: FSW
 * Date: 25/05/13
 * Time: 下午 02:28
 * To change this template use File | Settings | File Templates.
 */
public class FileParser {
    private String filePath;
    public FileParser(String filePath) {
        this.filePath = filePath;
    }

    public ArrayList<String[]> getData() {
        ArrayList<String[]> inputList= new ArrayList<String[]>();
        try{
            //Open file
            FileInputStream fstream = new FileInputStream(filePath);
            // Get the object of DataInputStream
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine;
            //skip the first line
            strLine = br.readLine();
            //Read File Line By Line
            while ((strLine = br.readLine()) != null)   {
                //split each line by |
                String[] strParts = strLine.split("\\|");
                inputList.add(strParts);
            }
            //Close the input stream
            in.close();
        }catch (Exception e){
            System.err.println("Error: " + e.getMessage());
        }
        return inputList;
    }
}
